package com.secxiot.provider.config;

import com.secxiot.common.exception.BaseException;
import com.secxiot.common.utils.DateUtils;
import com.secxiot.provider.user.service.UserService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.logging.Level;

@Log
@Component
@EnableScheduling
public class FileTimer {

    @Autowired
    private UserService userService;

    @Scheduled(cron = "0 0 2 * * ?")
    private void pushSMSNotice() {
        Date date = DateUtils.nextDay(-3);
        String format = DateUtils.getDate(date, "yyyy-MM-dd");
        log.log(Level.INFO, "删除日志文件:" + format);
        userService.deleteLogFile(format);
    }
}
